! Keepalived Configuration File (Managed by Ansible)
 
global_defs {
    vrrp_version 3
    enable_script_security
    script_user {{ keepalived_scripts_user }}
}
{% for item in keepalived_vip %}

vrrp_script keepalived-{{ item.id }}-promote {
    script "/usr/libexec/keepalived/{{ item.vrrp_script }} {{ item.check | default("") }}"
    interval 10
    weight 100
}
{% endfor %}
{% for item in keepalived_vip %}

vrrp_instance vip_{{ item.id }} {
    state {{ item.state }}
    interface {{ item.interface }}
    priority {{ item.priority }}
    virtual_router_id {{ item.id }}
    advert_int 1
    accept
    garp_master_refresh 5
    garp_master_refresh_repeat 1
    unicast_src_ip {{ keepalived_ip }}
    unicast_peer {
{% for item in keepalived_cluster_hosts %}
{% if item.ip != keepalived_ip %}
        {{ item.ip }}
{% endif %}
{% endfor %}
    }
    virtual_ipaddress {
        {{ item.vip }} dev {{ item.interface}} label {{ item.interface }}:{{ item.id }}
    }
    track_script {
        keepalived-{{ item.id }}-promote
    }
}
{% endfor %}
